<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>门票产品列表</title>
    <script src="__PUBLIC__/echarts/echarts.min.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__CSS__/admin.css" media="all">
</head>

<body>
<div class="layui-fluid main">
    <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
        <div class="layui-form-item" style="float: left;">
            <form class="layui-form serch" action="/admin/ticket/index.shtml" method="post">
                <div class="layui-form-item" style="float: left;">
                    <div class="layui-input-inline">
                        <input type="hidden" name="use_type" value="3">
                        <input type="text" name="tripname" lay-verify="title" value="{if isset($wherelist['tripname'])}{$wherelist['tripname']}{/if}" autocomplete="off" placeholder="请输入门票ID/名称/CODE" class="layui-input layui-btn-sm">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" name="supplierItemCode" lay-verify="title" value="{if isset($wherelist['supplierItemCode'])}{$wherelist['supplierItemCode']}{/if}" autocomplete="off" placeholder="请输入供应商产品号" class="layui-input layui-btn-sm">
                    </div>
                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="supplier_id" lay-search="">
                                <option value="" >供应商</option>
                                <option value="999999" {if  isset($wherelist['supplier_id']) AND "999999"==$wherelist['supplier_id']} selected{/if}>自营</option>
                                {volist name='supplier' id='vo'}
                                <option value="{$vo.id}" {if  isset($wherelist['supplier_id']) AND $vo.id==$wherelist['supplier_id']} selected{/if}>{$vo.name}</option>
                                {/volist}
                                <option value="1000000" {if  isset($wherelist['supplier_id']) AND "1000000"==$wherelist['supplier_id']} selected{/if}>其他</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="service_language" lay-search="">
                                <option value="">服务语言</option>
                                <option value="0" {if isset($wherelist['service_language']) AND $wherelist['service_language']=="0" }selected{/if}>中文</option>
                                <option value="1" {if isset($wherelist['service_language']) AND $wherelist['service_language']=="1" }selected{/if}>英文</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <select name="service_status" lay-search="">
                                <option value="">状态</option>
                                <option value="1" {if isset($wherelist['service_status']) AND $wherelist['service_status']=="1" }selected{/if}>售卖中</option>
                                <option value="2" {if isset($wherelist['service_status']) AND $wherelist['service_status']=="2" }selected{/if}>预售中</option>
                                <option value="0" {if isset($wherelist['service_status']) AND $wherelist['service_status']=="0" }selected{/if}>已下架</option>
                            </select>
                        </div>
                    </div>
                    <!--<div class="layui-input-inline">-->
                        <!--<div class="layui-inline">-->
                            <!--<select name="isTob" lay-search="">-->
                                <!--<option value="" >Tob上架状态</option>-->
                                <!--<option value="1" {if isset($wherelist['isTob']) && $wherelist['isTob']==1}selected{/if}>已上架</option>-->
                                <!--<option value="2" {if isset($wherelist['isTob']) && $wherelist['isTob']==2}selected{/if}>未上架</option>-->
                            <!--</select>-->
                        <!--</div>-->
                    <!--</div>-->

                    <div class="layui-input-inline">
                        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">搜索</button>
                        <a href="{:url('admin/ticket/ticketmake')}" class="layui-btn layui-btn-sm" target="_blank">
                            新增门票产品
                        </a>
                    </div>

                    <!--<div class="layui-input-inline">-->
                        <!--<a href="{:url('admin/ticket/index')}?exportFlag=1" class="layui-btn layui-btn-default layui-btn-sm">导出Excel</a>-->
                    <!--</div>-->
                </div>
            </form>

        </div>
    </fieldset>
    <table class="layui-table" lay-even="" lay-skin="line">
        <colgroup>
            <col width="50">
            <col width="300">
            <col width="100">
            <col width="200">
            <col width="100">
            <col width="100">
            <col width="100">
            <col width="100">
            <col width="150">
            <col width="100">
            <col width="100">
            <!--<col width="100">-->
            <!--<col width="100">-->
        </colgroup>
        <thead>
        <tr>
            <th>ID</th>
            <th>门票名称</th>
            <th>产品code</th>
            <th>供应商</th>
            <th>供应商产品号</th>
            <th>常见问题</th>
            <th>上传附件</th>
            <th>状态</th>
            <th>修改时间</th>
            <th>最后修改人</th>
            <!--<th>toB上架</th>-->
            <th>普通操作</th>
            <!--<th>升级操作</th>-->
        </tr>
        </thead>
        <tbody>
        {volist name="product" id="vo"}
        <tr>
            <td>{$vo.id}</td>
            <td><strong>{$vo.name}</strong></td>
            <td>{$vo.item_num}</td>
            <td>{$vo.supplier_name}</td>
            <td>{$vo.supplier_item_code}</td>
            <td>
                {if $vo.faq_flag>0}
                &nbsp;<a href="{:url('admin/faq/showFaq',['groupid'=>$vo.id,'typeid'=>1])}" class="layui-btn layui-btn-xs layui-btn-warm" target="_blank"  style="margin-right: 0;font-size:12px;">FAQ</a>
                {else}
                &nbsp;<a href="{:url('admin/faq/showFaq',['groupid'=>$vo.id,'typeid'=>1])}" class="layui-btn layui-btn-xs layui-btn-primary" target="_blank"  style="margin-right: 0;font-size:12px;">暂无</a>
                {/if}
            </td>
            <td>
                {if !empty($vo.up_url)}
                &nbsp;<a href="{:url('admin/product/savefile',['id'=>$vo.id,'typeid'=>2])}" class="layui-btn layui-btn-xs layui-btn-warm a_menu" target="_blank"  style="margin-right: 0;font-size:12px;">附件</a>
                {else}
                &nbsp;<a href="{:url('admin/product/savefile',['id'=>$vo.id,'typeid'=>2])}" class="layui-btn layui-btn-xs layui-btn-primary a_menu" target="_blank"  style="margin-right: 0;font-size:12px;">暂无</a>
                {/if}
            </td>
            <td>
                {if $vo.service_status==1}
                <span style="font-weight:bold;color: dodgerblue">售卖中</span>
                {elseif $vo.service_status==2}
                <span style="font-weight:bold;color: limegreen">预售中</span>
                {else}
                <span style="font-weight:bold;color: red">已下架</span>
                {/if}
            </td>
            <td>{$vo.update_time}</td>
            <td>{$vo.update_admin}</td>

            <!--<td style="font-size:10px;">-->
                <!--{if !empty($vo.show_toB) && $vo.show_toB==1}-->
                <!--<span style="color:limegreen;font-weight: bold;">已上架</span>-->
                <!--{else}-->
                <!--<span style="color:orangered;font-weight: bold;">未上架</span>-->
                <!--{/if}-->
            <!--</td>-->

            <td class="operation-menu">
                <a href="{:url('admin/ticket/ticketmake',['id'=>$vo.id])}" class="layui-btn layui-btn-xs"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px" target="_blank">门票产品编辑</a>
                <br>
                <a class="layui-btn layui-btn-xs layui-btn-danger delete"  codeid="{$vo.id}" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">删除</a>
            </td>

            <!--<td class="operation-menu">-->
                <!--{if !empty($vo.standard_id)}-->
                <!--{if $vo.page_index==1}-->
                <!--<a href="{:url('admin/standard/add',['id'=>$vo.standard_id])}" class="layui-btn layui-btn-xs layui-btn-normal" target="_blank" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">标品化配置</a>-->
                <!--{elseif $vo.page_index==2}-->
                <!--<a href="{:url('admin/standard/process',['id'=>$vo.standard_id])}" class="layui-btn layui-btn-xs layui-btn-normal" target="_blank" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">标品化配置</a>-->
                <!--{elseif $vo.page_index==3}-->
                <!--<a href="{:url('admin/standard/savebasic',['id'=>$vo.standard_id])}" class="layui-btn layui-btn-xs layui-btn-normal" target="_blank" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">标品化配置</a>-->
                <!--{elseif $vo.page_index==4}-->
                <!--<a href="{:url('admin/product/setsection',['id'=>$vo.standard_id])}" class="layui-btn layui-btn-xs layui-btn-normal" target="_blank" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">标品化配置</a>-->
                <!--{elseif $vo.page_index==5}-->
                <!--<a href="{:url('admin/standard/savegoods',['id'=>$vo.standard_id])}" class="layui-btn layui-btn-xs layui-btn-normal" target="_blank" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">标品化配置</a>-->
                <!--{else}-->
                <!--<a href="{:url('admin/standard/detail',['id'=>$vo.standard_id])}" class="layui-btn layui-btn-xs layui-btn-normal" target="_blank" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">标品化配置</a>-->
                <!--{/if}-->

                <!--<br>-->
                <!--{if $vo.show_toB==1}-->
                <!--<a codeid="{$vo.standard_id}" class="layui-btn layui-btn-xs layui-btn-danger downPro" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">下架ToB</a><br>-->
                <!--{else}-->
                <!--<a codeid="{$vo.standard_id}" class="layui-btn layui-btn-xs layui-btn-info openPro" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px;background-color:limegreen;">上架ToB</a><br>-->
                <!--{/if}-->
                <!--{else}-->
                <!--<a href="{:url('admin/standard/add',['product_id'=>$vo.id])}" target="_blank" class="layui-btn layui-btn-xs layui-btn-normal" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">标品化配置</a>-->
                <!--{/if}-->
            <!--</td>-->
        </tr>
        {/volist}
        </tbody>
    </table>
    <div>{$product->render()}</div>
    <div id="checkBox" style="display:none;">
        <style>
            .isok,.notok{
                font-size: 24px;line-height:24px;
            }
            .isok{
                color: #4caf50;
            }
            .notok{
                color: #ff5722;
            }
        </style>
        <div class="layui-row">
            <!--基础信息-->
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="box">
                            <div style="margin-left:20px;">
                                <form class="layui-form" id="checkInfo">

                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <script type="text/javascript">
        $('.delete').click(function(){
            var id = $(this).attr('codeid');
            layer.confirm('确定要删除?', function(index) {
                $.ajax({
                    url:"{:url('admin/product/deltrip')}",
                    data:{id:id},
                    success:function(res) {
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.reload();
                            },1500)
                        }
                    }
                })
            })
        });

        $('.addStandard').click(function(){
            var id = $(this).attr('codeid');
            $.ajax({
                url:"{:url('admin/product/addStandard')}",
                data:{id:id},
                success:function(res) {
                    layer.msg(res.msg);
                    if(res.code == 1) {
                        setTimeout(function(){
                            location.reload();
                        },1500)
                    }
                }
            });

        });

        $('.copy').click(function(){
            var id = $(this).attr('codeid');
            layer.confirm('确定复制吗:', {
                btn: ['产品','取消'],
                btn1: function() {
                    $.ajax({
                        url:"{:url('admin/product/copytrip')}",
                        data:{id:id, use_type:1},
                        success:function(res) {
                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.reload();
                                },1500)
                            }
                        }
                    })
                },
                btn2: function() {
                    layer.closeAll();
                }
            });
            return false;
        });
    </script>
    <script type="text/javascript">
        layui.use(['layer', 'form'], function(){
            var layer = layui.layer;
            var form = layui.form;
            $('.a_menu').click(function(){
                var url = $(this).attr('href');
                var a = 0;
                $.ajax({
                    url:url
                    ,async:false
                    ,success:function(res){
                        if(res.code == 0) {
                            layer.msg(res.msg);
                            a = 1;
                        }
                    }
                });
                if(a === 0) {
                    layer.open({
                        type:2,
                        content:url,
                        area: ['65%', '95%'],
                        end:function(){
                            location.reload();
                        }
                    });
                }
                return false;
            });

            $('.preview').click(function(){
                var url = $(this).attr('href');
                layer.open({
                    type:2,
                    content:url,
                    area: ['550px', '400px']
                });
                return false;
            });

            $('.a_faq').click(function(){
                var url = $(this).attr('href');
                layer.open({
                    title:"FAQ",
                    type:2,
                    content:url,
                    area: ['95%', '95%']
                });
                return false;
            });

            //标品配置
            //下架标品
            $(".downPro").click(function(){
                var id = $(this).attr('codeid');
                layer.confirm("您确定从ToB系统下架此标品吗？",function(index){
                    $.post("/admin/standard/changeToB",{'id':id,'show_toB':0},function(res){
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.href = res.url;
                            },1500)
                        }
                    },'json')
                })
            });
            var checkProTimer = null;
            var upPro = true;
            $(".openPro").click(function(){
                var id = $(this).attr('codeid');
                $.post("/admin/standard/checkProInfo",{'id':id},function(res){
                    var list = res.data.tips;
                    var goods_id = res.data.goods_id;
                    if(list.length<1){
                        layer.msg(res.msg);
                    }else{
                        openCheckPro(id,list,goods_id);
                        checkProTimer = setInterval(function(){
                            refreshCheckPro(id);
                        },1500)
                    }
                },'json')
            });
            //实时刷新检查标品数据
            function refreshCheckPro(id){
                $.post("/admin/standard/checkProInfo",{'id':id},function(res){
                    var list = res.data.tips;
                    var goods_id = res.data.goods_id;
                    if(list.length<1){
                        layer.msg(res.msg);
                    }else{
                        showCheckProResult(id,list,goods_id)
                    }
                },'json')
            }
            function showCheckProResult(id,data,goods_id){
                var showLink = true;
                var str = "";
                str += '<div class="layui-form-item">检测信息如下：</div>';
                $.each(data,function(i,v){
                    str += '<div class="layui-form-item">\n' +
                        '<label class="layui-form-label">'+i+'</label>\n' +
                        '<div class="layui-input-inline" style="margin:8px auto;">\n';
                    if(v=="1"){
                        str += '<i class="layui-icon isok">&#xe605;</i>\n';
                    }else{
                        str += '<i class="layui-icon notok">&#x1006;</i>\n';
                        if(showLink){
                            var url = checkLinkUrl(id,i,goods_id);
                            var url_class = "";
                            if(i=="商品套餐"){
                                url_class = "a_menu";
                            }
                            str += '<a href="'+url+'" class="layui-btn layui-btn-xs layui-btn-primary '+url_class+'" target="_blank" style="margin-top:-10px;margin-left:50px;">设置</a>\n';
                        }
                        showLink = false;
                    }
                    str += '</div>\n' +
                        '</div>';
                });
                $("#checkInfo").children().remove();
                $("#checkInfo").append(str);
                upPro = showLink;
                if(upPro){
                    clearInterval(checkProTimer);
                }
                return upPro;
            }
            //检测标品数据
            function openCheckPro(id,data,goods_id){
                upPro = showCheckProResult(id,data,goods_id);
                //打开一个弹窗 点击保存触发事件
                layer.open({
                    type: 1,
                    area: ['50%', '70%'],
                    btn: ['上架','取消'],
                    content: $('#checkBox'),
                    yes: function(index, layero) {
                        if(!upPro){
                            layer.msg("请补全以上缺省的信息！");
                            return false;
                        }
                        $.post("/admin/standard/changeToB",{'id':id,'show_toB':1},function(res){
                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.href = res.url;
                                },1500)
                            }
                        },'json');
                    },btn2:function(index){
                        clearInterval(checkProTimer);
                        layer.close(index);
                    },end:function(){
                        clearInterval(checkProTimer);
                    }
                })
            }
            //检测toB上架所需跳转链接
            function checkLinkUrl(id,name="",goods_id=0){
                var url = "";
                switch (name) {
                    case "关联商品":
                        url = "{:url('admin/standard/detail')}?id="+id+"#sourceBox";
                        break;
                    case "关联行程":
                        url = "{:url('admin/standard/detail')}?id="+id+"#tripBox";
                        break;
                    case "商品套餐":
                        url = "{:url('admin/goods/addclassify')}?id="+goods_id;
                        break;
                    case "商品价格":
                        url = "{:url('admin/goods/personsedit')}?id="+goods_id+"&standard_id="+id;
                        break;
                    default:
                        url = "";
                        break;
                }
                return url;
            }
            //切换是否toB显示
            form.on('switch(changeToB)', function(data){
                var id= $(this).attr('data-id');
                var is_show;
                if(data.elem.checked){
                    is_show =1;
                }else{
                    is_show =0;
                }
                $.ajax({
                    url:"{:url('admin/standard/changeToB')}",
                    data:{'id':id,'show_toB':is_show},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                    }
                })

            });
            //切换禁用启用
            form.on('switch(changeRecommend)', function(data){
                var id= $(this).attr('data-id');
                var is_recommend;
                if(data.elem.checked){
                    is_recommend =1;
                }else{
                    is_recommend =0;
                }
                $.ajax({
                    url:"{:url('admin/standard/changeRecommend')}",
                    data:{'id':id,'is_recommend':is_recommend},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                    }
                })
            });
        });
    </script>
</div>
</body>
</html>
